home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1986 September & October / rerun-1986-09-10.d64 / turtle tutor (.txt) < prev   
Commodore BASIC  |  2022-09-20  |  6KB  |  273 lines

  1. 10 rem arrays
  2. 12 dim b(12),a$(36),b$(36),c$(12)
  3. 14 :
  4. 16 rem title
  5. 18 poke 53280,7:poke 53281,7
  6. 20 a$="*":tl=40:print "[147]     ";a$;:for f=1 to 3
  7. 22 for a=1 to 6:gosub 2750:print "[157] [157]";a$;:next a
  8. 24 for a=1 to 5:gosub 2750:print "[157] [157][157]";a$;:next a
  9. 26 gosub 2750:print "[157] [157]";a$;:read b$:gosub 2950
  10. 28 for a=1 to 5:print "[157] ";:gosub 2750:print "[157]";a$;:gosub 2750:next a
  11. 29 next f:gosub 2550:d=0
  12. 30 :
  13. 32 rem instructions
  14. 34 b$="[147][144]     elmer's instructions for you:"
  15. 36 tl=1:gosub 2950:print "[157] [157]";a$;
  16. 38 for a=1 to len(b$)-3:print "[157] [157][157]*";:gosub 2750:next a
  17. 40 read b$:if b$="end" then 60
  18. 42 print "[157] [157]";a$;:gosub 2950
  19. 44 read b$:if b$="end" then 60
  20. 46 print "[157] [157]";a$;:a=len(b$):for c=1 to a
  21. 48 print "[157]";mid$(b$,a-c+1,1)"[157][157]";a$;
  22. 50 gosub 2750:next c:goto 40
  23. 60 tl=40
  24. 62 get b$:if b$<>"" then 100
  25. 64 print "[157] ";:gosub 2750
  26. 66 print "[157]";a$;:gosub 2750:goto 62
  27. 100 :
  28. 140 rem variables
  29. 170 read b$:if b$="end"thenbl=b:goto200
  30. 180 b=b+1:b$(b)=b$:b(b)=len(b$)
  31. 190 read c(b):goto 170
  32. 200 s$="             "
  33. 210 er$="[145]"+s$+s$+s$+"[145]"
  34. 220 tl=50:al=36:d=54272:u=10
  35. 699 :
  36. 700 rem ....restart address
  37. 710 :
  38. 730 rem statement list display
  39. 735 poke 53280,3:poke 53281,3:poke 646,6
  40. 740 print "[147]";:n=18:for o=1 to 18
  41. 750 print "";right$(str$(o),2);". ";
  42. 760 print "";a$(o);tab(20);
  43. 770 print "";right$(str$(o+n),2);". ";
  44. 780 print "";a$(o+n):next o:print
  45. 790 if q=1 then 980
  46. 800 :
  47. 810 rem line # input
  48. 830 input "line #, 'e' or 'new'";i$
  49. 840 print er$:if i$="e" then 1610
  50. 850 if i$<>"new" then 870
  51. 860 for a=1 to 36:a$(a)="":next:goto710
  52. 870 i=len(i$):if i<1 or i>3 then 940
  53. 880 if i$="0" then 940
  54. 890 n=asc(i$):if n<49 or n>57 then 940
  55. 900 n=asc(right$(i$,1))
  56. 910 if n<49 and n>57 then 940
  57. 920 a=val(i$)
  58. 930 if a>0 and a=<al then 980
  59. 940 gosub 2500:if u=0 then 810
  60. 950 print "[147]"
  61. 960 goto 710
  62. 970 :
  63. 980 rem statement display
  64. 1000 q=1:print "[145]";
  65. 1010 for m=1 to 3:for n=0 to 3
  66. 1020 b=m+n*3:if b>bl then 1040
  67. 1030 print tab(n*10);b$(b);
  68. 1040 next n:print:next m
  69. 1050 print "i[158]nsert    d[158]elete    ";
  70. 1060 print "b[158]ack to line #"
  71. 1070 :
  72. 1080 rem statement input
  73. 1100 print "line";a;:i$="":input i$
  74. 1110 print er$:if i$="" then gosub 2500:goto 1070
  75. 1120 if i$="i" then 1540
  76. 1130 if i$="d" then 1580
  77. 1140 if i$="b" then q=0:goto 710
  78. 1150 :
  79. 1160 rem is 'i$' valid?
  80. 1180 b=0:i=len(i$)
  81. 1190 b=b+1:if b>bl then gosub 2500:goto 1070
  82. 1200 if left$(i$,b(b))<>b$(b) then 1190
  83. 1210 rem ....stmt #c
  84. 1220 c=c(b):if c>0 then 1260
  85. 1230 rem ....stmt type 0
  86. 1240 if i$=b$(b) then a$(a)=i$:q=0:goto 710
  87. 1250 goto 1370
  88. 1260 m$=right$(i$,i-b(b))
  89. 1270 gosub 2590
  90. 1280 j$=m$:j=len(j$):if c>1 then 1420
  91. 1290 rem ....stmt type 1
  92. 1300 if j=0 or j>2 then 1370
  93. 1310 n=asc(left$(j$,1))
  94. 1320 if n<48 or n>57 then 1370
  95. 1330 n=asc(right$(j$,1))
  96. 1340 if n<48 or n>57 then 1370
  97. 1350 n=val(j$):if b=8 and n<16 then 1460
  98. 1360 if b<>8 and n>0 then 1460
  99. 1370 gosub 2500:goto 1070
  100. 1420 if c>2 then 1480
  101. 1430 rem ....stmt type 2
  102. 1440 if j<>1 then 1370
  103. 1450 n=asc(j$):if n<33 or n>95 then 1370
  104. 1460 rem ....i$ is valid statement
  105. 1470 a$(a)=b$(b)+" "+j$:q=0:goto 710
  106. 1480 if c>3 then 1370
  107. 1490 rem ....stmt type 3
  108. 1500 if mid$(i$,5,1)=" " then 1520
  109. 1510 i$=left$(i$,4)+" "+mid$(i$,5)
  110. 1520 n=len(i$):if n<6 or n>15 then 1370
  111. 1530 a$(a)=i$:q=0:goto 710
  112. 1540 rem ....insert blank line
  113. 1550 for m=35 to a step -1
  114. 1560 a$(m+1)=a$(m):next m
  115. 1570 a$(a)="":q=0:goto 710
  116. 1580 rem ....delete line
  117. 1590 if a=36 then 1600
  118. 1595 for m=a to 35:a$(m)=a$(m+1):next
  119. 1600 a$(36)="":q=0:goto 710
  120. 1610 :
  121. 1620 rem begin execution
  122. 1640 x=1:y=1:rem    initial position
  123. 1650 e=2:rem        initial pen position
  124. 1660 h$="*":rem     initial character
  125. 1670 l=6:rem        initial color #
  126. 1680 poke 53280,5:rem  border color
  127. 1690 print "[147]":gosub 2770:gosub 2710
  128. 1700 rem ....statement list
  129. 1710 for a=1 to al:a$=a$(a)
  130. 1720 if a$="" then 2330
  131. 1730 b=0
  132. 1740 b=b+1
  133. 1750 if left$(a$,b(b))<>b$(b) then 1740
  134. 1760 on b goto 1780,1850,1920,1990,2060,2100,2130,2170,2210,2290
  135. 1770 :
  136. 1780 rem ....right
  137. 1790 m$=right$(a$,len(a$)-b(b))
  138. 1800 gosub 2590:m=val(m$)
  139. 1810 for n=1 to m:gosub 2370
  140. 1820 x=x+1:if x=41 then x=1
  141. 1830 gosub 2710:next n:goto 2330
  142. 1840 :
  143. 1850 rem ....up
  144. 1860 m$=right$(a$,len(a$)-b(b))
  145. 1870 gosub 2590:m=val(m$)
  146. 1880 for n=1 to m:gosub 2370
  147. 1890 y=y-1:if y=0 then y=25
  148. 1900 gosub 2710:next n:goto 2330
  149. 1910 :
  150. 1920 rem ....down
  151. 1930 m$=right$(a$,len(a$)-b(b))
  152. 1940 gosub 2590:m=val(m$)
  153. 1950 for n=1 to m:gosub 2370
  154. 1960 y=y+1:if y=26 then y=1
  155. 1970 gosub 2710:next n:goto 2330
  156. 1980 :
  157. 1990 rem ....left
  158. 2000 m$=right$(a$,len(a$)-b(b))
  159. 2010 gosub 2590:m=val(m$)
  160. 2020 for n=1 to m:gosub 2370
  161. 2030 x=x-1:if x=0 then x=40
  162. 2040 gosub 2710:next n:goto 2330
  163. 2050 :
  164. 2060 rem ....pen up
  165. 2070 if e=0 then e=1
  166. 2080 goto 2330
  167. 2090 :
  168. 2100 rem ....pen down
  169. 2110 e=0:goto 2330
  170. 2120 :
  171. 2130 rem ....char
  172. 2140 h$=right$(a$,1):gosub 2770
  173. 2150 p=983+x+y*40:poke p,k
  174. 2152 gosub 2750:goto 2330
  175. 2160 :
  176. 2170 rem ....color
  177. 2180 l=val(mid$(a$,6)):p=983+x+y*40
  178. 2190 poke p+d,l:gosub 2750:goto 2330
  179. 2200 :
  180. 2210 rem ....text
  181. 2220 a$=mid$(a$,6):m=len(a$)
  182. 2225 x=x-1:if x=0 then x=40
  183. 2230 gosub 2370:j=k:for n=1 to m
  184. 2240 h$=mid$(a$,n,1):gosub 2770
  185. 2250 x=x+1:if x=41 then x=1
  186. 2260 gosub 2710:next n
  187. 2270 k=j:f=1:m=1:goto 1810
  188. 2280 :
  189. 2290 rem ....stop
  190. 2300 a$=""
  191. 2310 get a$:if a$="" then 2310
  192. 2320 goto 2330
  193. 2330 next a:q=0:goto 710
  194. 2340 :
  195. 2350 rem subroutines
  196. 2360 :
  197. 2370 rem ....erase previous point?
  198. 2380 if f=1 then f=0:return
  199. 2390 if e=1 then e=2:return
  200. 2400 if e=2 then poke p+d,v:poke p,w
  201. 2410 return
  202. 2420 :
  203. 2430 rem ....instruction input
  204. 2440 print ""
  205. 2450 print "       press any key to ";
  206. 2460 print "continue":a$=""
  207. 2470 get a$:if a$="" then 2470
  208. 2480 print "[147]":return
  209. 2490 :
  210. 2500 rem ....error message
  211. 2510 print ,"[144]i don't understand that"
  212. 2520 gosub 2560:print er$
  213. 2530 print ,"please try again"
  214. 2540 gosub 2560:print er$:return
  215. 2550 :
  216. 2560 rem ....screen message delay
  217. 2570 for t=1 to 500:next t:return
  218. 2580 :
  219. 2590 rem ....truncate m$
  220. 2600 if m$="" then return
  221. 2610 m=asc(left$(m$,1))
  222. 2620 if m=32 then 2640
  223. 2630 if m<>160 then 2650
  224. 2640 m$=right$(m$,len(m$)-1):goto 2610
  225. 2650 if m$="" then return
  226. 2660 m=asc(right$(m$,1))
  227. 2670 if m=32 then 2690
  228. 2680 if m<>160 then return
  229. 2690 m$=left$(m$,len(m$)-1):goto 2650
  230. 2700 :
  231. 2710 rem ....poke screen character
  232. 2720 p=983+x+y*40
  233. 2730 v=peek(p+d):wl=w:w=peek(p)
  234. 2740 poke p+d,l:poke p,k
  235. 2750 for t=1 to tl:next t:return
  236. 2760 :
  237. 2770 rem ....calc screen display value
  238. 2780 h=asc(h$):if h<64 then k=h:return
  239. 2790 k=h-64:return
  240. 2800 :
  241. 2950 for c=1 to len(b$)
  242. 2960 print "[157]";mid$(b$,c,1);a$;
  243. 2970 gosub 2750:next c:return
  244. 3000 :
  245. 3002 rem fixed data
  246. 3004 :
  247. 3006 rem ....player instructions
  248. 3008 data "[144]hi, i'm elmer.","i'm a turtle.","let's play a game....."
  249. 3010 data "elmer is a tiny turtle who can draw and"
  250. 3012 data "  write all over the screen if you give"
  251. 3014 data "   him a list of simple instructions.  "
  252. 3016 data "                                       "
  253. 3018 data "first, enter either a line number on   "
  254. 3020 data "  the list, or 'new' to erase the whole"
  255. 3022 data "   list, or 'e' to watch elmer follow  "
  256. 3024 data "  your instructions.                   "
  257. 3026 data "                                       "
  258. 3028 data "if you entered a list line number, you  "
  259. 3030 data "    can then enter one of the instruc- "
  260. 3032 data "   tions shown below the list.         "
  261. 3033 data "                                       "
  262. 3034 data "you can also delete or insert lines.   "
  263. 3036 data "                                       "
  264. 3037 data "                                       "
  265. 3038 data "    press any key to start playing...."
  266. 3040 data end
  267. 3110 :
  268. 3120 rem ....elmer instructions
  269. 3130 data right,1,up,1,down,1,left,1
  270. 3140 data pen up,0,pen down,0,char,2
  271. 3150 data color,1,text,3,stop,0
  272. 3160 data end
  273.